package com.Java.train.business.controller.daily;

import com.Java.train.business.req.DailyTrainStationReq;
import com.Java.train.business.service.daily.DailyTrainStationService;
import com.Java.train.common.response.CommonResp;
import com.Java.train.business.entity.DTO.DailyTrainStationDTO;
import com.Java.train.business.req.daily.DailyTrainStationQueryReq;
import com.Java.train.common.response.PageResp;
import com.Java.train.business.entity.DailyTrainStation;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

import java.util.List;
/**
* @author luomoxingchen
* @since 2024-09-24
*/
@RestController
@RequestMapping("/daily-train-station")
public class DailyTrainStationController {
//    /**
//     * 重载了Contriller方法，让前端传入的String类型时间格式对实体类的类型进行匹配
//     * @param binder 前端传入参数
//     */
//    @InitBinder
//    public void initBinder(WebDataBinder binder) {
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        dateFormat.setLenient(false);
//        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
//    }

    @Autowired
    private DailyTrainStationService dailyTrainStationService;


    @GetMapping("/admin/query-list")
    @ApiOperation("DailyTrainStation查询全部")
    public CommonResp<PageResp<DailyTrainStationDTO>> queryList(@Valid DailyTrainStationQueryReq dailyTrainStationQueryReq){
        PageResp<DailyTrainStationDTO> list = dailyTrainStationService.queryList(dailyTrainStationQueryReq);
        return new CommonResp<>(list);
    }

    @PostMapping("/admin/save")
    @ApiOperation("DailyTrainStation修改")
    public CommonResp<Object> update(@Valid @RequestBody DailyTrainStation dailyTrainStation) {
        return dailyTrainStationService.modify(dailyTrainStation);
    }


    @DeleteMapping(value = "/admin/delete/{ids}")
    @ApiOperation("DailyTrainStation删除(单个条目)")
    public CommonResp<Object> remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        return dailyTrainStationService.remove(ids);
    }

    @GetMapping("/query-by-train-code")
    public CommonResp<List<DailyTrainStationDTO>> queryAllByTrain(@Valid DailyTrainStationReq dailyTrainStationReq){
        List<DailyTrainStationDTO> list = dailyTrainStationService.queryAllByTrain(dailyTrainStationReq);
        return new CommonResp<>(list);
    }
}
